*********************************
***  Facebook tools paper - Data analysis
*** Created: 06/07/2021
*** Last updated: 23/01/2023

use "Combined dataset.dta", clear

********OBJECTIVES AND SAMPLE, COMPLETES**********
use "Combined dataset.dta", clear
*keep if country=="Uk" & Progress==100 & consent==1 & conversion==1
*keep if country=="Uk" & Progress==100 & consent==1 & traffic==1
*keep if country=="Uk" & Progress==100 & consent==1 & conversion_notargeting==1
keep if country=="Uk" & Progress==100 & consent==1 & conversion_cross==1

tab young 
csgof young, expperc(71 29) 

tab  middle_aged 
csgof middle_aged, expperc(66 34) 

tab nocollege 
csgof nocollege, expperc(30 70) 

tab  female 
csgof female, expperc(49 51) 

tab  notin 
csgof notin, expperc(57 43) 

tab  non_partisan 
csgof non_partisan, expperc(52 48) 


use "Combined dataset.dta", clear
*keep if country=="Turkey" & Progress==100 & consent==1 & conversion==1
*keep if country=="Turkey" & Progress==100 & consent==1 & traffic==1

*keep if country=="Turkey" & Progress==100 & consent==1 & conversion_notargeting==1
*keep if country=="Turkey" & Progress==100 & consent==1 & conversion_single==1
keep if country=="Turkey" & Progress==100 & consent==1 & conversion_cross==1

tab young 
csgof young, expperc(63 37) 

tab  middle_aged 
csgof middle_aged, expperc(60 40) 

tab nocollege 
csgof nocollege, expperc(20 80) 

tab  female 
csgof female, expperc(50 50) 

tab  notin 
csgof notin, expperc(52 48) 

tab  non_partisan 
csgof non_partisan, expperc(68 32) 

use "Combined dataset.dta", clear
*keep if country=="Spain" & Progress==100 & consent==1 & conversion==1
*keep if country=="Spain" & Progress==100 & consent==1 & traffic==1
*keep if country=="Spain" & Progress==100 & consent==1 & conversion_notargeting==1
*keep if country=="Spain" & Progress==100 & consent==1 & conversion_single==1
keep if country=="Spain" & Progress==100 & consent==1 & conversion_cross==1

tab young 
csgof young, expperc(78 22) 

tab  middle_aged 
csgof middle_aged, expperc(59 41) 

tab nocollege 
csgof nocollege, expperc(27 73) 

tab  female 
csgof female, expperc(48 52) 

tab  notin 
csgof notin, expperc(40 60) 

tab  non_partisan 
csgof non_partisan, expperc(59 41) 

use "Combined dataset.dta", clear
*keep if country=="Czechia" & Progress==100 & consent==1 & conversion==1
*keep if country=="Czechia" & Progress==100 & consent==1 & traffic==1
*keep if country=="Czechia" & Progress==100 & consent==1 & conversion_notargeting==1
*keep if country=="Czechia" & Progress==100 & consent==1 & conversion_single==1
keep if country=="Czechia" & Progress==100 & consent==1 & conversion_cross==1

tab young 
csgof young, expperc(75 25) 

tab  middle_aged 
csgof middle_aged, expperc(64 36) 

tab nocollege 
csgof nocollege, expperc(17 83) 

tab  female 
csgof female, expperc(49 51) 

tab  notin 
csgof notin, expperc(18 82) 

tab  non_partisan 
csgof non_partisan, expperc(39 61) 


********OBJECTIVES AND SAMPLE, NON-COMPLETES**********
use "Combined dataset.dta", clear

*keep if country=="Uk"
*keep if country=="Turkey"
*keep if country=="Spain"
keep if country=="Czechia"

tab young if Progress!=100 & consent==1 & conversion==1
tab  middle_aged if Progress!=100 & consent==1 & conversion==1
tab nocollege if Progress!=100 & consent==1 & conversion==1
tab  female if Progress!=100 & consent==1 & conversion==1
tab  notin if Progress!=100 & consent==1 & conversion==1
tab  non_partisan  if Progress!=100 & consent==1 & conversion==1
tab conversion if Progress!=100 & consent==1 
tab young  if Progress!=100 & consent==1 & traffic==1
tab  middle_aged  if Progress!=100 & consent==1 & traffic==1
tab nocollege  if Progress!=100 & consent==1 & traffic==1
tab  female  if Progress!=100 & consent==1 & traffic==1
tab  notin  if Progress!=100 & consent==1 & traffic==1
tab  non_partisan  if Progress!=100 & consent==1 & traffic==1
tab traffic if Progress!=100 & consent==1 

*******RESPONSE QUALITY COMPLETES******
use "Combined dataset.dta", clear

*keep if country=="Uk"
*keep if country=="Turkey"
keep if country=="Spain"
*keep if country=="Czechia"

tab attentive if Progress==100 & consent==1 & conversion==1
tab attentive if Progress==100 & consent==1 & traffic==1
sum Duration__in_seconds_ if Progress==100&consent==1&conversion==1, detail
sum Duration__in_seconds_ if Progress==100&consent==1&traffic==1, detail
tab openended_responded if Progress==100&consent==1&conversion==1
tab openended_responded if Progress==100&consent==1&traffic==1
sum wordcount if Progress==100&consent==1&traffic==1&wordcount!=0
sum wordcount if Progress==100&consent==1&conversion==1&wordcount!=0 
tab contactinfo_provided if Progress==100&consent==1&conversion==1
tab contactinfo_provided if Progress==100&consent==1&traffic==1


*******RESPONSE QUALITY FOR TARGETING TOOLS******
use "Combined dataset.dta", clear

*keep if country=="Uk"
*keep if country=="Turkey"
*keep if country=="Spain"
keep if country=="Czechia"

tab attentive if Progress==100 & consent==1 & conversion_notargeting==1
tab attentive if Progress==100 & consent==1 & conversion_single==1
tab attentive if Progress==100 & consent==1 & conversion_cross==1

sum Duration__in_seconds_ if Progress==100&consent==1&conversion_notargeting==1, detail
sum Duration__in_seconds_ if Progress==100&consent==1&conversion_single==1, detail
sum Duration__in_seconds_ if Progress==100&consent==1&conversion_cross==1, detail

tab openended_responded if Progress==100&consent==1&conversion_notargeting==1
tab openended_responded if Progress==100&consent==1&conversion_single==1
tab openended_responded if Progress==100&consent==1&conversion_cross==1


sum wordcount if Progress==100&consent==1&conversion_notargeting==1&wordcount!=0 
sum wordcount if Progress==100&consent==1&conversion_single==1&wordcount!=0 
sum wordcount if Progress==100&consent==1&conversion_cross==1&wordcount!=0 

tab contactinfo_provided if Progress==100&consent==1&conversion_notargeting==1
tab contactinfo_provided if Progress==100&consent==1&conversion_single==1
tab contactinfo_provided if Progress==100&consent==1&conversion_cross==1


*******RESPONSE QUALITY NON-COMPLETES******
use "Combined dataset.dta", clear

*keep if country=="Uk"
*keep if country=="Turkey"
*keep if country=="Spain"
keep if country=="Czechia"

tab attentive if Progress!=100 & consent==1 & conversion==1
tab attentive if Progress!=100 & consent==1 & traffic==1
sum Duration__in_seconds_ if Progress!=100&consent==1&conversion==1, detail
sum Duration__in_seconds_ if Progress!=100&consent==1&traffic==1, detail
tab openended_responded if Progress!=100&consent==1&conversion==1
tab openended_responded if Progress!=100&consent==1&traffic==1
sum wordcount if Progress!=100&consent==1&traffic==1&wordcount!=0
sum wordcount if Progress!=100&consent==1&conversion==1&wordcount!=0 
tab contactinfo_provided if Progress!=100&consent==1&conversion==1
tab contactinfo_provided if Progress!=100&consent==1&traffic==1

****************DEMOGRAPHIC ANALYSIS GROUPS*********************
use "Combined dataset.dta", clear

*keep if country=="Uk" & consent==1 & Progress==100 & conversion_n==1 
*keep if country=="Uk" & consent==1 & Progress==100 & conversion_s==1 
keep if country=="Uk" & consent==1 & Progress==100 & conversion_c==1 

tab young 
csgof young, expperc(71 29) 

tab middle 
csgof middle, expperc(66 34) 

tab nocollege 
csgof nocollege, expperc(30 70) 

tab female 
csgof female, expperc(49 51) 

use "Combined dataset.dta", clear
*keep if country=="Turkey" & consent==1 & Progress==100 & conversion_n==1 
*keep if country=="Turkey" & consent==1 & Progress==100 & conversion_s==1 
keep if country=="Turkey" & consent==1 & Progress==100 & conversion_c==1 

tab young 
csgof young, expperc(63 37) 

tab middle 
csgof middle, expperc(60 40) 

tab nocollege 
csgof nocollege, expperc(20 80) 

tab female 
csgof female, expperc(50 50) 

use "Combined dataset.dta", clear
*keep if country=="Spain" & consent==1 & Progress==100 & conversion_n==1 
*keep if country=="Spain" & consent==1 & Progress==100 & conversion_s==1 
keep if country=="Spain" & consent==1 & Progress==100 & conversion_c==1 

tab young 
csgof young, expperc(78 22) 

tab middle 
csgof middle, expperc(59 41) 

tab nocollege 
csgof nocollege, expperc(27 73) 

tab female 
csgof female, expperc(48 52) 

use "Facebook tools combined dataset.dta", clear
*keep if country=="Czechia" & consent==1 & Progress==100 & conversion_n==1 
*keep if country=="Czechia" & consent==1 & Progress==100 & conversion_s==1 
keep if country=="Czechia" & consent==1 & Progress==100 & conversion_c==1 

tab young 
csgof young, expperc(75 25) 

tab middle 
csgof middle, expperc(64 36) 

tab nocollege 
csgof nocollege, expperc(17 83) 

tab female 
csgof female, expperc(49 51) 


****************DEMOGRAPHIC ANALYSIS CROSS-GROUPS*********************

use "Combined dataset.dta", clear

*keep if country=="Uk" & consent==1 & Progress==100 & conversion_n==1 
*keep if country=="Uk" & consent==1 & Progress==100 & conversion_s==1 
keep if country=="Uk" & consent==1 & Progress==100 & conversion_c==1 

tab group1 
csgof group1, expperc(92 8) 

tab group2 
csgof group2, expperc(90 10) 

tab group3 
csgof group3, expperc(95 5) 

tab group4 
csgof group4, expperc(95 5) 

tab group5 
csgof group5, expperc(90 10) 

tab group6 
csgof group6, expperc(90 10) 

tab group7 
csgof group7, expperc(94 6) 

tab group8 
csgof group8, expperc(94 6) 

tab group9 
csgof group9, expperc(84 16) 

tab group10 
csgof group10, expperc(87 13) 

tab group11 
csgof group11, expperc(96 4) 

tab group12 
csgof group12, expperc(95 5) 


use "Combined dataset.dta", clear
*keep if country=="Turkey" & consent==1 & Progress==100 & conversion_n==1 
*keep if country=="Turkey" & consent==1 & Progress==100 & conversion_s==1 
keep if country=="Turkey" & consent==1 & Progress==100 & conversion_c==1 

tab group1 
csgof group1, expperc(86 14) 

tab group2 
csgof group2, expperc(85 15) 

tab group3 
csgof group3, expperc(95 5) 

tab group4 
csgof group4, expperc(95 5) 

tab group5 
csgof group5, expperc(83 17) 

tab group6 
csgof group6, expperc(83 17) 

tab group7 
csgof group7, expperc(97 3) 

tab group8 
csgof group8, expperc(96 4) 

tab group9 
csgof group9, expperc(92 8) 

tab group10 
csgof group10, expperc(90 10) 

tab group11 
csgof group11, expperc(99 1) 

tab group12 
csgof group12, expperc(98 2) 

use "Combined dataset.dta", clear
*keep if country=="Spain" & consent==1 & Progress==100 & conversion_n==1 
*keep if country=="Spain" & consent==1 & Progress==100 & conversion_s==1 
keep if country=="Spain" & consent==1 & Progress==100 & conversion_c==1 

tab group1 
csgof group1, expperc(93 7) 

tab group2 
csgof group2, expperc(92 8) 

tab group3 
csgof group3, expperc(96 4) 

tab group4 
csgof group4, expperc(97 3) 

tab group5 
csgof group5, expperc(88 12) 

tab group6 
csgof group6, expperc(87 13) 

tab group7 
csgof group7, expperc(93 7) 

tab group8 
csgof group8, expperc(94 6) 

tab group9 
csgof group9, expperc(82 18) 

tab group10 
csgof group10, expperc(86 14) 

tab group11 
csgof group11, expperc(97 3) 

tab group12 
csgof group12, expperc(96 4) 

use "Combined dataset.dta", clear
*keep if country=="Czechia" & consent==1 & Progress==100 & conversion_n==1 
*keep if country=="Czechia" & consent==1 & Progress==100 & conversion_s==1 
keep if country=="Czechia" & consent==1 & Progress==100 & conversion_c==1 

tab group1 
csgof group1, expperc(91 9) 

tab group2 
csgof group2, expperc(89 11) 

tab group3 
csgof group3, expperc(97 3) 

tab group4 
csgof group4, expperc(98 2) 

tab group5 
csgof group5, expperc(86 14) 

tab group6 
csgof group6, expperc(85 15) 

tab group7 
csgof group7, expperc(96 4) 

tab group8 
csgof group8, expperc(96 4) 

tab group9 
csgof group9, expperc(81 19) 

tab group10 
csgof group10, expperc(86 14) 

tab group11 
csgof group11, expperc(98 2) 

tab group12 
csgof group12, expperc(97 3) 


************FIGURES*********

use "Combined dataset.dta", clear

*FOR UK*
twoway (line N_participants day if objective=="conversion" & country=="Uk" & day<6, lcolor(black) lpattern(solid)) ///
(line N_participants day if objective=="traffic" & country=="Uk" & day<6, lcolor(black) lpattern(dash)) ///
(line N_participants day if objective=="reach" & country=="Uk" & day<6, lcolor(black) lpattern(dot)), ///
legend(order(1 "Conversion" 2 "Traffic" 3 "Reach")) ///
graphregion(fcolor(white) lcolor(none) ifcolor(white) ilcolor(none)) xscale(range(1 15)) yscale (range (100 (100)600)) xlabel(1(2)15) ylabel(100 (100)600) xtitle (Days) ytitle (Participants) title (UK) name(uk, replace)


*FOR TURKEY*
twoway (line N_participants day if objective=="conversion" & country=="Turkey" & day<5, lcolor(black) lpattern(solid)) ///
(line N_participants day if objective=="traffic" & country=="Turkey" & day<5, lcolor(black) lpattern(dash)), ///
legend(order(1 "Conversion" 2 "Traffic" )) ///
graphregion(fcolor(white) lcolor(none) ifcolor(white) ilcolor(none)) xscale(range(1 15)) yscale (range (100 (100)600)) xlabel(1(2)15) ylabel(100 (100)600) xtitle (Days) ytitle (Participants) title (Turkey) name(turkey, replace)


*FOR SPAIN*
twoway (line N_participants day if objective=="conversion" & country=="Spain" & day<15, lcolor(black) lpattern(solid)) ///
(line N_participants day if objective=="traffic" & country=="Spain" & day<15, lcolor(black) lpattern(dash)), ///
legend(order(1 "Conversion" 2 "Traffic" )) ///
graphregion(fcolor(white) lcolor(none) ifcolor(white) ilcolor(none)) xscale(range(1 15)) yscale (range (100 (100)600)) xlabel(1(2)15) ylabel(100 (100)600) xtitle (Days) ytitle (Participants) title (Spain) name(spain, replace)

*FOR CZECH REPUBLIC*
twoway (line N_participants day if objective=="conversion" & country=="Czechia" & day<15, lcolor(black) lpattern(solid)) ///
(line N_participants day if objective=="traffic" & country=="Czechia" & day<15, lcolor(black) lpattern(dash)), ///
legend(order(1 "Conversion" 2 "Traffic" )) ///
graphregion(fcolor(white) lcolor(none) ifcolor(white) ilcolor(none)) xscale(range(1 15)) yscale (range (100 (100)600)) xlabel(1(2)15 ) ylabel(100 (100)600) xtitle (Days) ytitle (Participants) title (Czech Republic) name(czechia, replace)

graph combine uk turkey spain czechia


************FIGURES 2*********

use "Combined dataset.dta", clear

*FOR UK*
twoway (line N_participants_recruitment day if objective=="conversion" & country=="Uk" & recruitment=="notargeting" & day<6, lcolor(black) lpattern(solid)) ///
(line N_participants_recruitment day if objective=="conversion" & country=="Uk" & recruitment=="singletargeting" & day<6, lcolor(black) lpattern(dot)) ///
(line N_participants_recruitment day if objective=="conversion" & country=="Uk" & recruitment=="crosstargeting" & day<6, lcolor(black) lpattern(dash)), ///
legend(order(1 "No targeting" 2 "Single Targeting" 3 "Cross Targeting" )) ///
graphregion(fcolor(white) lcolor(none) ifcolor(white) ilcolor(none)) xscale(range(1 15)) yscale (range (100 (100)600)) xlabel(1(2)15 ) ylabel(100 (100)600) xtitle (Days) ytitle (Participants) title (UK) name(uk_recruitment, replace)


*FOR TURKEY*
twoway (line N_participants_recruitment day if objective=="conversion" & country=="Turkey" & recruitment=="notargeting" & day<5, lcolor(black) lpattern(solid)) ///
(line N_participants_recruitment day if objective=="conversion" & country=="Turkey" & recruitment=="singletargeting" & day<5, lcolor(black) lpattern(dot)) ///
(line N_participants_recruitment day if objective=="conversion" & country=="Turkey" & recruitment=="crosstargeting" & day<5, lcolor(black) lpattern(dash)), ///
legend(order(1 "No targeting" 2 "Single Targeting" 3 "Cross Targeting" )) ///
graphregion(fcolor(white) lcolor(none) ifcolor(white) ilcolor(none)) xscale(range(1 15)) yscale (range (100 (100)600)) xlabel(1(2)15 ) ylabel(100 (100)600) xtitle (Days) ytitle (Participants) title (Turkey) name(turkey_recruitment, replace)


*FOR SPAIN*
twoway (line N_participants_recruitment day if objective=="conversion" & country=="Spain" & recruitment=="notargeting" & day<15, lcolor(black) lpattern(solid)) ///
(line N_participants_recruitment day if objective=="conversion" & country=="Spain" & recruitment=="singletargeting" & day<15, lcolor(black) lpattern(dot)) ///
(line N_participants_recruitment day if objective=="conversion" & country=="Spain" & recruitment=="crosstargeting" & day<15, lcolor(black) lpattern(dash)), ///
legend(order(1 "No targeting" 2 "Single Targeting" 3 "Cross Targeting" )) ///
graphregion(fcolor(white) lcolor(none) ifcolor(white) ilcolor(none)) xscale(range(1 15)) yscale (range (100 (100)600)) xlabel(1(2)15 ) ylabel(100 (100)600) xtitle (Days) ytitle (Participants) title (Spain) name(spain_recruitment, replace)

*FOR CZECH REPUBLIC*
twoway (line N_participants_recruitment day if objective=="conversion" & country=="Czechia" & recruitment=="notargeting" & day<15, lcolor(black) lpattern(solid)) ///
(line N_participants_recruitment day if objective=="conversion" & country=="Czechia" & recruitment=="singletargeting" & day<15, lcolor(black) lpattern(dot)) ///
(line N_participants_recruitment day if objective=="conversion" & country=="Czechia" & recruitment=="crosstargeting" & day<15, lcolor(black) lpattern(dash)), ///
legend(order(1 "No targeting" 2 "Single Targeting" 3 "Cross Targeting" )) ///
graphregion(fcolor(white) lcolor(none) ifcolor(white) ilcolor(none)) xscale(range(1 15)) yscale (range (100 (100)600)) xlabel(1(2)15 ) ylabel(100 (100)600) xtitle (Days) ytitle (Participants) title (Czech Republic) name(czechia_recruitment, replace)

graph combine uk_recruitment turkey_recruitment spain_recruitment czechia_recruitment






